﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting;
using Configuration.ServerApi.Param;
using Configuration.ServerApi.Service;
using System.Threading.Tasks;

namespace Configuration.ServerApi.Controllers
{
    /// <summary>
    /// 菜单管理Controller
    /// </summary>
    [Authorize("AuthJwt")]
    [Route("api/[controller]")]
    [ApiController]
    public class MenuController : ControllerBase
    {
        private readonly IHostEnvironment HostEnvironment;
        private readonly IMenuService MenuService;

        #region 构造函数

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="hostEnvironment"></param>
        /// <param name="menuService"></param>
        public MenuController(IHostEnvironment hostEnvironment,
            IMenuService menuService)
        {
            HostEnvironment = hostEnvironment;
            MenuService = menuService;
        }

        #endregion

        #region 获取菜单列表

        /// <summary>
        /// 获取菜单列表
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("MenuList")]
        public async Task<IActionResult> MenuList(SearchModel param)
        {
            return await MenuService.MenuList(param);
        }

        #endregion

        #region 获取菜单详情

        /// <summary>
        /// 获取菜单详情
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("MenuDetail")]
        public async Task<IActionResult> MenuDetail(SearchModel param)
        {
            return await MenuService.MenuDetail(param);
        }

        #endregion

        #region 提交菜单信息

        /// <summary>
        /// 提交菜单信息
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("SubmitMenu")]
        public async Task<IActionResult> SubmitMenu(UpdateModel param)
        {
            return await MenuService.SubmitMenu(param);
        }

        #endregion

        #region 批量删除菜单信息

        /// <summary>
        /// 批量删除菜单信息
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("DelMenu")]
        public async Task<IActionResult> DelMenu(UpdateModel param)
        {
            return await MenuService.DelMenu(param);
        }

        #endregion

        #region 获取树形菜单列表

        /// <summary>
        /// 获取树形菜单列表
        /// </summary>
        [HttpPost]
        [Route("TreeMenuList")]
        public async Task<IActionResult> TreeMenuList()
        {
            return await MenuService.TreeMenuList();
        }

        #endregion

        #region 获取全部树形菜单节点列表

        /// <summary>
        /// 获取全部树形菜单节点列表
        /// </summary>
        [HttpPost]
        [Route("AllTreeMenuNodeList")]
        public async Task<IActionResult> AllTreeMenuNodeList()
        {
            return await MenuService.AllTreeMenuNodeList();
        }

        #endregion

        #region 获取登录用户拥有的权限菜单列表

        /// <summary>
        /// 获取登录用户拥有的权限菜单列表
        /// </summary>
        [HttpPost]
        [Route("UserRoleMenuList")]
        public async Task<IActionResult> UserRoleMenuList()
        {
            return await MenuService.UserRoleMenuList();
        }

        #endregion

        #region 获取登录用户拥有的树形权限菜单列表

        /// <summary>
        /// 获取登录用户拥有的树形权限菜单列表
        /// </summary>
        [HttpPost]
        [Route("UserRoleTreeMenuList")]
        public async Task<IActionResult> UserRoleTreeMenuList()
        {
            return await MenuService.UserRoleTreeMenuList();
        }

        #endregion

        #region 获取指定角色拥有的权限菜单列表

        /// <summary>
        /// 获取指定角色拥有的权限菜单列表
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("UserRoleMenuListById")]
        public async Task<IActionResult> UserRoleMenuListById(SearchModel param)
        {
            return await MenuService.UserRoleMenuListById(param);
        }

        #endregion

        #region 提交角色菜单授权信息

        /// <summary>
        /// 提交角色菜单授权信息
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("SubmitUserRoleMenu")]
        public async Task<IActionResult> SubmitUserRoleMenu(UpdateModel param)
        {
            return await MenuService.SubmitUserRoleMenu(param);
        }

        #endregion

    }
}
